<template>
	<view class="container">
		
		<view class="reportView">
			<uni-row class="uni-row">
				<uni-col>
					<text class="title">上级机构：</text>
					<view class="input-item flex align-center">
					  <uni-data-picker class="picker" placeholder="请选择上级机构" :map="map2" popup-title="请选择上级机构" :localdata="deptList" v-model="FormData.parentId">
					  </uni-data-picker>
					</view>
				</uni-col>
			</uni-row>
			<uni-row class="uni-row">
				<uni-col>
					<text class="title">机构名称：</text>
					<view class="input-item flex align-center">
					  <input  placeholder="请输入角色名称" placeholder-class="place" v-model="FormData.name" class="input" type="text"  maxlength="30" />
					</view>
				</uni-col>
			</uni-row>
			<uni-row class="uni-row">
				<uni-col :span="12">
					<text class="title">负责人:</text>
					<view class="input-item flex align-center">
						<uni-data-picker placeholder="请选择负责人" placeholder-class="place" class="picker"
						  v-model="FormData.leaderUserId"
						  :localdata="userList"
							:map="map"
						></uni-data-picker >
					</view>
				</uni-col>
				<uni-col :span="12">
					<text class="title">机构状态:</text>
					<view class="input-item flex align-center">
					  <uni-data-select
					  placeholder="请选择"
					  placeholder-class="place"
					    v-model="FormData.status"
					    :localdata="range"
					  ></uni-data-select>
					</view>
				</uni-col>
			</uni-row>
			<uni-row class="uni-row">
				<uni-col>
					<text class="title">联系电话：</text>
					<view class="input-item flex align-center">
					  <input  placeholder="请输入联系电话" placeholder-class="place" v-model="FormData.phone" class="input" type="text"  maxlength="30" />
					</view>
				</uni-col>
			</uni-row>
		</view>
		<view class="submit-view">
			<button class='submit'  @tap="clickBtn">完成</button>
		</view>
	</view>
</template>
<script>
	import { getDeptById ,getUserSimple,getDeptList,createDept,updateDept} from '@/api/system/system'
	export default{
		data(){
			return{
				id:null,
				range:[{
					text:'开启',
					value:0
				},{
					text:'关闭',
					value:1
				}],
				map:{
					text:'nickname',
					value:'id'
				},
				map2:{
					text:'name',
					value:'id'
				},
				FormData:{
					id:null,
					sort:1
				},
				userList:[],
				deptList:[]
				
			}
		},
		onLoad(e) {
			if(e.id != null && e.id != ''){
				this.id = e.id
				this.getData();
			}
			this.getUser()
		},
		created() {
			
		},
		methods:{

			getData(){
				let data={
					id:this.id
				}
				getDeptById(data).then(res=>{
					this.FormData = res.data
				})
			},
			getUser(){
				getUserSimple().then(res=>{
					this.userList=res.data
				})
				getDeptList().then(res=>{
					this.deptList=this.handleTree(res.data,'id');
				})
			},
			clickBtn(){
				if(this.FormData.id == null){
					createDept(this.FormData).then(res=>{
						uni.navigateBack({
							delta:1
						})
					})
				}else{
					updateDept(this.FormData).then(res=>{
						if(res.data === true){
							uni.navigateBack({
								delta:1
							})
						}
					})
				}
				
			}
		}
	}
</script>

<style lang="scss">
	.container{
		background-color: #fff;
		height: 100vh;
		.reportView{
			width: calc(100% - 80rpx);
			margin: 0 auto;
			.title{
				font-size: 14px;
				font-family: Inter-Bold, Inter;
				font-weight: bold;
				color: #000000;
				line-height: 40px;
			}
			.textarea{
				
			}
			
			.input-item{
				background-color: #ffffff;
				height: 30px;
				border-radius: 5px 5px 5px 5px;
				opacity: 1;
				border: 1px solid #508CFF;
				padding: 20px;
				margin-left: 10px;
				.place{
					font-size: 12px;
				}
				/deep/ .uni-select{
					border: none;
					border-bottom: none;
					padding-left: 0;
				}
			}
			.uni-row{
				margin-bottom: 10px;
			}
			
		}
		.picker{
			/deep/ .input-value-border{
				border: none;
				box-shadow: none;
			}
			/deep/ .selected-list{
				width: 230px;
				overflow: hidden;
			}
		}
		.submit{
			color: #fff;
			width: 100px;
			height: 40px;
			font-size: 14px;
			line-height: 40px;
			background: #508CFF;
			border-radius: 5px 5px 5px 5px;
			position: absolute;
			bottom: 50px;
			left: 36%;
		}
	}
</style>